package org.ocean.online.wicket;

import org.apache.wicket.RuntimeConfigurationType;
import org.apache.wicket.protocol.http.WebApplication;
import org.ocean.hibernate.SessionFactoryUtil;
import org.ocean.online.auth.ClientOn;
import org.ocean.online.sys.DispatchPage;
import org.ocean.online.sys.OnlineConfig;
import org.ocean.online.sys.SimpleDispatchPage;
import org.ocean.online.sys.SimpleInitPage;
import org.ocean.online.web.Login;
import org.ocean.online.web.Registe;
import org.ocean.online.web.setting.AccountManager;
import org.ocean.online.web.workspace.DesignModel;
import org.ocean.online.web.workspace.DownLoad;
import org.ocean.online.web.workspace.EditFile;
import org.ocean.online.web.workspace.LoadJson;
import org.ocean.online.web.workspace.PackageExplorer;
import org.ocean.online.web.workspace.WorkSpace2;
import org.ocean.online.web.workspace.tool.EditModelData;

/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 * 
 * @see org.ocean.Start#main(String[])
 */
public class WicketApplication extends WebApplication
{    	
	/**
	 * @see org.apache.wicket.Application#getHomePage()
	 */
	@Override
	public Class getHomePage()
	{
		return DispatchPage.class;
	}

	/**
	 * @see org.apache.wicket.Application#init()
	 */
	@Override
	public void init()
	{
		super.init();
		super.getMarkupSettings().setDefaultMarkupEncoding("utf-8");
		
//		this.mountPage("/loadres", LoadResource.class);
		// add your configuration here
		initsys();
	}

	@Override
	public RuntimeConfigurationType getConfigurationType() {
		return RuntimeConfigurationType.DEVELOPMENT;
	}

	private void initsys(){
		OnlineConfig.init();
		System.out.println("projectType="+OnlineConfig.getProperty("projectType"));
		if("mutiple".equals(OnlineConfig.getProperty("projectType"))){
			mutilMount();
			SessionFactoryUtil.init();
//			ThreadGuard.start();
		}else{
			simpleMount();
		}
	}

	private void simpleMount() {
		
		this.mountPage("/", SimpleDispatchPage.class);
		this.mountPage("/install", SimpleInitPage.class);
	}

	private void mutilMount() {
		this.mountPage("/", DispatchPage.class);
		this.mountPage("/registe", Registe.class);
		this.mountPage("/login", Login.class);
		this.mountPage("/loadtree", PackageExplorer.class);
		this.mountPage("/workspace2", WorkSpace2.class);
		this.mountPage("/model", DesignModel.class);
		this.mountPage("/editModelData", EditModelData.class);
		this.mountPage("/loadjson", LoadJson.class);
		this.mountPage("/uploadFile", UploadifyFileProcessPage.class);
		this.mountPage("/editFile", EditFile.class);
		this.mountPage("/download", DownLoad.class);
		this.mountPage("/accounts", AccountManager.class);
		this.mountPage("/clienton", ClientOn.class);
	}
}
